package NewCode;

import java.util.List;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/10/22 23:41
 */
public class FindKthToTailDemo {
    public ListNode FindKthToTail(ListNode head,int k) {
        if (head == null){
            return head;
        }
        int length = 0;
        ListNode cur = head;
        while (cur!=null){
            length++;
            cur = cur.next;
        }
        int jump = length - k;
        if (jump>=0){
            for (int i = 0; i < jump; i++) {
                head = head.next;
            }
            return head;
        }else {
            return null;
        }
    }
}
 class ListNode {
     int val;
     ListNode next = null;

     ListNode(int val) {
         this.val = val;
     }
 }
